package com.wondream.myframework.app.common.util;

import com.github.pagehelper.ISelect;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wondream.myframework.app.vo.base.PageParamVO;
import com.wondream.myframework.app.vo.base.PageVO;
import lombok.AllArgsConstructor;

/**
 * @param <Param> 泛型request
 * @param <Result> 泛型response
 */
@AllArgsConstructor
public class PageUtils<Param, Result> {

    /**
     * 分页查询
     *
     * @param param 请求参数DTO
     * @param param lambda like: () -> list(param.getParam())
     * @return 分页集合
     */
    public PageVO<Result> page(PageParamVO<Param> param, ISelect select) {
        PageInfo<Result> resultList = PageHelper.startPage(param).doSelectPageInfo(select);
        PageVO<Result> toList = new PageVO<>();
        toList.setPageNo(resultList.getPageNum());
        toList.setPageSize(resultList.getPageSize());
        toList.setPages(resultList.getPages());
        toList.setTotal((int) resultList.getTotal());
        toList.setRecords(resultList.getList());
        return toList;
    }

//    /**
//     * 集合查询
//     *
//     * @param param 查询参数
//     * @return 查询响应
//     */
//    List<Result> list(Param param);
}